package com.printer;

public class PaperImpl implements Paper {
	private StringBuilder content = new StringBuilder();
	private int maxWordsInLine;
	private int maxLinesInPage;
	private int wordsInLine;
	private int linesInPage;
	private int page;

	public void setMaxWordsInLine(int maxWordsInLine) {
		this.maxWordsInLine = maxWordsInLine;
	}

	public void setMaxLinesInPage(int maxLinesInPage) {
		this.maxLinesInPage = maxLinesInPage;
	}

	@Override
	public void printChar(char c) {
		content.append(c);
		wordsInLine++;
		if (wordsInLine == maxWordsInLine) {
			linesInPage++;
			wordsInLine = 0;
			content.append("\n");
		}
		if (linesInPage == maxLinesInPage) {
			page++;
			linesInPage = 0;
			content.append("--->第" + page + "页<---\n\n");
		}
	}

	@Override
	public String getContent() {
		if (linesInPage == 0) {
			return content.toString();
		} else {
			return content.append("\n--->第" + (page + 1) + "页<---").toString();
		}
	}

}
